<template>
    <div class="top">
        <div class="content">
            <div class="left" @click="toHome">
                <img src="@/assets/logo.png" alt="">
                <p>预约挂号统一平台</p>
            </div>
            <div class="right">
                <p class="login" @click="login" v-if="!userStore.userInfo.name">登录/注册</p>
                <el-dropdown v-else trigger="click">
                    <span class="el-dropdown-link">
                        {{ userStore.userInfo.name }}
                        <el-icon class="el-icon--right">
                            <arrow-down />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item>实名认证</el-dropdown-item>
                            <el-dropdown-item>挂号订单</el-dropdown-item>
                            <el-dropdown-item>就诊人管理</el-dropdown-item>
                            <el-dropdown-item @click="loginout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ArrowDown } from "@element-plus/icons-vue";
import userInfoStore from "@/store/modules/user";
const userStore = userInfoStore()
//引入路由
import { useRouter } from 'vue-router'
//创建路由
const $router = useRouter()
//路由跳转
const toHome = () => {
    $router.push({ path: '/home' })
}
//点击登录
const login = () => {
    userStore.visiable = !userStore.visiable
}
//退出登录
const loginout=()=>{
    //清除仓库
    userStore.logout()
    //跳转首页
    $router.push({path:'/home'})
}
</script>

<style lang="less" scoped>
.top {
    width: 100%;
    height: 70px;
    display: flex;
    justify-content: center;

    .content {
        width: 1200px;
        height: 70px;
        display: flex;
        justify-content: space-between;

        .left {
            display: flex;
            align-items: center;
            justify-content: center;

            p {
                font-size: 20px;
                color: #55a6fe;
                cursor: pointer;
            }

            img {
                width: 50px;
                height: 50px;
                border-radius: 50%;
                margin-right: 10px;
                cursor: pointer;
            }
        }

        .right {
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14px;
            cursor: pointer;

            .help {
                margin-right: 10px;
            }
        }
    }
}
</style>